package cn.jjzd.info.controller;

import cn.jjzd.info.response.SelectResponse;
import cn.jjzd.info.service.BusinessTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("business")
public class BusinessController {
    @Autowired
    private BusinessTypeService businessTypeService;

    @GetMapping("list")
    public ResponseEntity<List<SelectResponse>> queryList(){
        List<SelectResponse> list = businessTypeService.queryList();
        if(list == null || CollectionUtils.isEmpty(list)){
            return ResponseEntity.notFound().build();
        }
        return ResponseEntity.ok(list);
    }

    @GetMapping("{id}")
    public ResponseEntity<SelectResponse> queryBusinessTypeId(@PathVariable("id")Long id){
        SelectResponse result = businessTypeService.queryBusinessTypeId(id);
        if(result == null){
            return ResponseEntity.notFound().build();
        }
        return ResponseEntity.ok(result);
    }

}
